/*
* jlb
*/
package com.jlb.ore.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.user.entity.User;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.ore.entity.OreRecord;
import com.jlb.ore.service.OreRecordSV;

/**
 * 矿石产生记录 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/oreRecord")
@Slf4j
@Api(value = "矿石产生记录控制器", description = "矿石产生记录控制器")
public class OreRecordCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private OreRecordSV oreRecordSV;

    @Resource
    private UserSV userSV;

    /**
     * 查询OreRecord一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询OreRecord一个详情信息", notes = "查询OreRecord一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id) {
        if (id == null) {
            return null;
        }
        OreRecord oreRecord = oreRecordSV.load(id);
        log.info(JSON.toJSONString(oreRecord));
        return BeanRet.create(true, "查询成功", oreRecord);
    }


    /**
     * 根据条件id查询OreRecord一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询OreRecord一个详情信息", notes = "查询OreRecord一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        OreRecord oreRecord = oreRecordSV.loadById(id);
        log.info(JSON.toJSONString(oreRecord));
        return BeanRet.create(true, "查询成功", oreRecord);
    }


    /**
     * 查询OreRecord信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询OreRecord信息集合", notes = "查询OreRecord信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "用户账户", required = true, paramType = "query"),

            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(String account, @ApiIgnore OreRecord oreRecord, Integer curPage, Integer pageSize) {
        Page<OreRecord> page = new Page<>(pageSize, curPage);
        if (StringUtils.isNotBlank(account)) {
            User user = userSV.loadByAccount(account);
            if (user == null) {
                return BeanRet.create(true, "查询成功", page);
            }
            oreRecord.setUserCode(user.getCode());
        }
        List<OreRecord> oreRecords = oreRecordSV.list(oreRecord, page.genRowStart(), page.getPageSize());
        page.setVoList(oreRecords);
        int total = oreRecordSV.count(oreRecord);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询OreRecord信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询OreRecord信息集合", notes = "查询OreRecord信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, Integer curPage, Integer pageSize) {
        Page<OreRecord> page = new Page<OreRecord>(pageSize, curPage);
        List<OreRecord> oreRecords = oreRecordSV.list(id, page.genRowStart(), page.getPageSize());
        page.setVoList(oreRecords);
        int total = oreRecordSV.count(id);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计OreRecord信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计OreRecord信息数量根据主键", notes = " 统计OreRecord信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id) {
        return oreRecordSV.count(id);
    }

    /**
     * 统计OreRecord信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计OreRecord信息数量", notes = "统计OreRecord信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subUserCode", value = "下级编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益比例", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore OreRecord oreRecord) {
        if (oreRecord == null) {
            return oreRecordSV.count(new HashMap());
        } else {
            return oreRecordSV.count(oreRecord);
        }
    }


    /**
     * 创建OreRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建OreRecord", notes = "创建OreRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subUserCode", value = "下级编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益比例", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore OreRecord oreRecord) {
        oreRecordSV.save(oreRecord);
        return BeanRet.create(true, "创建成功", oreRecord);
    }


    /**
     * 修改OreRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改OreRecord", notes = "修改OreRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subUserCode", value = "下级编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益比例", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石数量", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore OreRecord oreRecord) {
        oreRecordSV.modify(oreRecord);
        return BeanRet.create(true, "修改成功", oreRecord);
    }

    /**
     * 删除OreRecord
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除OreRecord", notes = "删除OreRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id) {
        oreRecordSV.delete(id);
        return BeanRet.create(true, "删除OreRecord成功");
    }

}
